﻿
@{
    var node = ViewBag.node as Stardust.ConfigCenterWeb.Code.Entities.ServerNode;
    var contractList = ViewBag.contractList as List<Stardust.ConfigCenterWeb.Code.Entities.ServiceContract>;
    var title = node.ServiceName + "[v" + node.Version + "]";
    ViewBag.Title = title;

    Func<string, string> GetPlatformClass = (platform) =>
    {
        return platform == ".NET" ? "info" : "warning";
    };
}


<link href="~/css/highlight.min.css" rel="stylesheet" />

<script src="~/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<style>
    .treeview {
        font-size: 1.125rem;
    }
</style>



<div class="margin10">

    <div class="grid condensed">
        <div class="row cells5">
            <div class="cell">
                <div style="position:fixed;">
                    <h2>
                        @if (node.Status == Stardust.Common.Enum.ServerNodeStatus.Normal)
            {
                            <span class="mif-spinner5 fg-green mif-ani-spin" title="Normal"></span>
                        }
                        else if (node.Status == Stardust.Common.Enum.ServerNodeStatus.Disconnect)
                        {
                            <span class="mif-warning fg-red mif-ani-flash" title="Disconnect"></span>
                        }
                        else if (node.Status == Stardust.Common.Enum.ServerNodeStatus.Disabled)
                        {
                            <span class="mif-not" title="Disabled"></span>
                        }
                        @node.ServiceName

                        <small>
                            v@(node.Version)
                            <span class="tag @GetPlatformClass(node.Platform)">@node.Platform</span>
                        </small>
                    </h2>

                    <hr class="bg-blue" />
                    <div class="treeview" data-role="treeview">
                        <ul>

                            @foreach (var gp in contractList.GroupBy(x => x.ControllerName))
                            {
                                <li class="node collapsed">
                                    <a class="leaf" href="#@gp.Key" title="@gp.First().ControllerDescription">@gp.Key</a>
                                    <span class="node-toggle"></span>
                                    <ul>
                                        @foreach (var item in gp)
                                        {
                                            <li title="@item.ActionDescription"><a href="#@(item.ControllerName + "." + item.ActionName)" class="leaf">@item.ActionName</a></li>
                                        }
                                    </ul>
                                </li>
                            }
                        </ul>
                    </div>
                </div>
            </div>
            <div class="cell colspan4">

                <ul class="step-list">

                    @foreach (var gp in contractList.GroupBy(x => x.ControllerName))
                    {
                        <div id="@gp.Key"></div>
                        foreach (var item in gp)
                        {
                            <li id="@(item.ControllerName + "." + item.ActionName)">
                                <h3 class="no-margin-top">@(item.ControllerName + "." + item.ActionName)  @item.ActionDescription</h3>
                                <hr class="bg-green">
                                <h4>参数：</h4>
                                <pre><code class="json ps">
@item.Params</code>
</pre>
                                <h4>返回值：</h4>
                                <pre><code class="json">
@item.Result</code>
</pre>
                                <a href="javascript:;" ps="@item.Params" onclick="showInvoke(this,'@item.ControllerName','@item.ActionName')">测试</a>
                            </li>
                        }
                    }
                </ul>

                <br />
                <br />
                &nbsp;
            </div>

        </div>
    </div>
</div>


<div class="padding20" data-role="dialog" id="invoke_dialog" data-overlay="true" data-close-button="true" data-overlay-color="op-dark">
    <h3 id="invoke_title"></h3>
    <hr class="bg-green" />
    <div class="grid" style="width:1000px;">

        <div class="row cells2">
            <div class="cell">
                <p>参数：</p>
                <textarea id="jsonParams" style="width:100%" rows="30"></textarea>
            </div>
            <div class="cell">
                <p>返回值：</p>
                <textarea id="jsonResult" style="width:100%" rows="30"></textarea>
            </div>
        </div>
        <button type="button" id="invoke_button" class="button primary">调用</button>
    </div>

</div>



<script>

    var serviceName = "@node.ServiceName";
    var version = "@node.Version";

    function showInvoke(self, controllerName, actionName) {
        metroDialog.open("#invoke_dialog");

        var defaultJsonParams = $(self).attr("ps");
        $("#jsonParams").val(defaultJsonParams);
        $("#jsonResult").val("");
        $("#invoke_title").text(controllerName + "." + actionName);

        $("#invoke_button").unbind().click(function () {
            var data = {
                serviceName: serviceName,
                version: version,
                controllerName: controllerName,
                actionName: actionName,
                jsonParams: $("#jsonParams").val()
            };

            $.post("@Url.Action("invoke")", data, function (result) {
                $("#jsonResult").val(result);
            });
        });
    }
</script>